<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>System Monitor</title>
    <style>
        /* General Reset */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #6e7dff, #3a4bfa);
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: #fff;
        }

        .container {
            background-color: #ffffff;
            border-radius: 10px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
            padding: 40px;
            width: 100%;
            max-width: 600px;
            text-align: center;
            transition: transform 0.3s ease;
        }

        .container:hover {
            transform: translateY(-5px);
        }

        h1 {
            color: #333;
            font-size: 28px;
            margin-bottom: 30px;
        }

        .stat {
            margin: 20px 0;
            font-size: 18px;
            color: #333;
        }

        /* Progress bar container */
        .progress-container {
            width: 100%;
            height: 25px;
            background-color: #f0f0f0;
            border-radius: 20px;
            margin: 15px 0;
            overflow: hidden;
            box-shadow: inset 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        /* Progress bar */
        .progress-bar {
            height: 100%;
            border-radius: 20px;
            text-align: center;
            font-weight: bold;
            line-height: 25px;
            color: white;
            transition: width 1s ease-in-out;  /* Smooth transition */
        }

        /* Media Queries for Responsiveness */
        @media (max-width: 600px) {
            .container {
                padding: 20px;
                width: 90%;
            }

            h1 {
                font-size: 24px;
            }

            .stat {
                font-size: 16px;
            }
        }

    </style>
</head>
<body>
<div class="container">
    <h1>System Monitor</h1>
    <div class="stat">CPU Load</div>
    <div class="progress-container">
        <div id="cpuBar" class="progress-bar">0%</div>
    </div>
    <div class="stat">Free Memory</div>
    <div class="progress-container">
        <div id="memoryBar" class="progress-bar">0%</div>
    </div>
    <div class="stat">Swap Usage</div>
    <div class="progress-container">
        <div id="swapBar" class="progress-bar">0%</div>
    </div>
</div>

<script>
    function updateProgressBar(id, percentage, color) {
        var bar = document.getElementById(id);
        bar.style.width = percentage + '%';
        bar.style.backgroundColor = color;
        bar.innerText = percentage.toFixed(2) + '%';
    }

    setInterval(function() {
        fetch('/api/system-stats')
            .then(response => response.json())
            .then(data => {
                updateProgressBar('cpuBar', data.cpuLoad, '#ff5722');
                updateProgressBar('memoryBar', (data.freeMemory / data.totalMemory) * 100, '#4caf50');
                updateProgressBar('swapBar', (data.swapUsed / data.swapTotal) * 100, '#2196f3');
            });
    }, 2000);
</script>
</body>
</html>
